#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define int long long

signed main()
{
    int n = 0, k = 0;
    cin >> n >> k;
    vector<int> arr(n + 1);
    for(int i = 1; i <= n; ++i)
    {
        cin >> arr[i];
    }
    sort(arr.begin(), arr.end());
    vector<int> sum(n + 1);
    for(int i = 1; i <= n; ++i)
    {
        sum[i] = arr[i] + sum[i - 1];
    }
    
    int left = 1, right = 1, ret = 1;
    while(right <= n)
    {
        int mid = (right + left) >> 1;
        int cost = (2 * mid - left - right) * arr[mid] 
            - (sum[mid - 1] - sum[left- 1]) + (sum[right] - sum[mid]);
        while(right <= n && cost <= k) // 两个while都能AC
        {
            ret = max(ret, right - left + 1);
            ++right;
            mid = (right + left) >> 1;
            cost = (2 * mid - left - right) * arr[mid] 
            - (sum[mid - 1] - sum[left- 1]) + (sum[right] - sum[mid]);
        }
        ++left;
        
        /*while(cost > k) // 两个while都能AC
        {
            ++left;
            mid = (right + left) >> 1;
            cost = (2 * mid - left - right) * arr[mid] 
            - (sum[mid - 1] - sum[left- 1]) + (sum[right] - sum[mid]);
        }
        ret = max(ret, right - left + 1);
        ++right;*/
    }
    cout << ret;
    return 0;
}